﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QbiconEditor
{

  public class QMapCollectorItem
  {
    public QMap qmap = new QMap();

    public int activeLayer = 0;

    public List<QObject> selectedObjects = new List<QObject>();
    public List<QPoint> selectedPoints = new List<QPoint>();

    public QMapCollectorItem(QMap map, int layerNum, List<QObject> selObjects, List<QPoint> selPoints)
    {
      this.qmap = QHelper.CopyQMap(map);
      this.activeLayer = layerNum;

      foreach (QObject qob in selObjects)
      {
        QObject fo = qmap.Layers[activeLayer].Objects.Find(q => q.Name == qob.Name);

        if (fo != null)
        {
          this.selectedObjects.Add(fo);
        }
      }

      foreach (QPoint qp in selPoints)
      {
        selectedPoints.Add(QHelper.CopyQPoint(qp));
      }
    }
  }

  public static class QMapCollector
  {
    private static List<QMapCollectorItem> stack = new List<QMapCollectorItem>();
   
    public static void Push(QMapCollectorItem item)
    {
      QMapCollectorItem it = new QMapCollectorItem(item.qmap,
                                                   item.activeLayer,
                                                   item.selectedObjects,
                                                   item.selectedPoints);

      stack.Insert(0, it);
    }

    public static QMapCollectorItem Pop()
    {
      if (stack.Count > 0)
      {
        QMapCollectorItem item = stack[0];
        stack.RemoveAt(0);

        return item;
      }

      return null;
    }
  }
}
